<?php

namespace App\Exports\Pay;

use App\Exports\Export;

class WalletExport extends Export
{

    /**
     * 映射标题行
     *
     * @return array
     */
    protected function headings(): array
    {
        return trans('view.pay.order.wallet.headings');
    }

    /**
     * 映射数据行
     *
     * @param \Illuminate\Database\Eloquent\Model $item
     * @return array
     */
    protected function map($item): array
    {
        return [
            $item->sn,
            $item->uid,
            $item->org->name ?? $item->plat_code,
            $item->account_id,
            $this->paymentList[$item->payment] ?? $item->payment,
            empty($item->consume) ? null : json_encode($item->consume),
            empty($item->take_back) ? null : json_encode($item->take_back),
            $this->statusList[$item->status] ?? $item->status,
            timestamp_to_datetime($item->created),
            timestamp_to_datetime($item->updated),
            !isset($item->usd['consume']) ? null : json_encode($item->usd['consume']),
            !isset($item->usd['take_back']) ? null : json_encode($item->usd['take_back']),
        ];
    }

    /**
     * 类型
     *
     * @var array
     */
    protected $paymentList;

    /**
     * 状态
     *
     * @var array
     */
    protected $statusList;

    /**
     * 初始化操作
     */
    protected function init()
    {
        // 类型
        $this->paymentList = trans('view.pay.order.wallet.paymentList');

        // 状态
        $this->statusList = trans('view.pay.order.wallet.statusList');

        // 文件名称
        $this->filename = trans('view.pay.order.wallet.filename');
    }
}
